package com.gk.panda.apis.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gk.panda.apis.dto.PatrolmanSaveDto;
import com.gk.panda.apis.dto.PatrolmanSearchDto;
import com.gk.panda.apis.log.Log;
import com.gk.panda.apis.service.PatrolmanService;
import com.gk.panda.commons.result.Result;
import com.gk.panda.pojo.Patrolman;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/patrolman")
@Api(tags = "巡护人员信息")
public class PatrolmanController {

    @Autowired
    private PatrolmanService patrolmanService;

    @ApiOperation(value = "查询当前机构巡护人员姓名列表")
    @GetMapping("/listName")
    public Result<List<String>> listPatrolman() {
        return Result.ok(patrolmanService.listPatrolman());
    }

    @ApiOperation(value = "分页查询巡护人员信息列表")
    @GetMapping()
    public Result<Page<Patrolman>> pagePatrolman(PatrolmanSearchDto dto) {
        return Result.ok(patrolmanService.pagePatrolman(dto));
    }

    @ApiOperation(value = "添加巡护人员")
    @Log
    @PostMapping()
    public Result<String> addPatrolman(@RequestBody PatrolmanSaveDto dto) {
        return patrolmanService.addPatrolman(dto);
    }

    @ApiOperation(value = "修改巡护人员")
    @Log
    @PutMapping()
    public Result<String> updatePatrolman(@RequestBody Patrolman patrolman) {
        boolean update = patrolmanService.updateById(patrolman);
        if (update) return Result.write(200,"修改成功");
        return Result.write(201,"修改失败");
    }

    @ApiOperation(value = "删除巡护人员")
    @Log
    @DeleteMapping("/{id}")
    public Result<String> deletePatrolman(@PathVariable("id") int id) {
        boolean remove = patrolmanService.removeById(id);
        if (remove) return Result.write(200,"删除成功");
        return Result.write(201,"删除失败");
    }
}
